<template>
	<scroll-view class="tab bgw pd30" scroll-y="true">
		<view class="commonlyItem" v-for="i in list" @click="getChoose(i.rp,i.typestr,i.arr)">
			<view class="title">{{i.title}}</view>
			<view class="commonly"><text class="text">{{i.typestr}}</text><text v-for="item in i.arr">{{item.name}}{{item.num}}{{item.danwei}};</text></view>
		</view>
		<view class="based" v-if="hidden">暂未添加处方</view>
		<!-- <view class="commonlyItem">
			<view class="title">养血温润肠方</view>
			<view class="commonly">
				<text>中华饮片</text>何首乌60.0g，当归70.0g，生白芍90.0g，何60.0g，当归70.0g，首乌60.0g，当归70.0g，生白芍90.0g，何60.0g，当归70.0g生白芍90.0g，何首90…
			</view>
		</view> -->
		<!-- <drag-button :isDock="true" @btnClick="btnClick"/> -->
	</scroll-view>
</template>

<script>
	import {
		jdf
	} from '../../../request/api.js'
	import dragButton from "@/components/drag-button/drag-button.vue";
	export default {
		name: "tab33",
		components: {
			dragButton
		},
		data() {
			return {
				list: [],
				hidden:false
			};
		},
		// 组件里要使用vue的生命周期函数 mounted
		mounted() {
			console.log('开始获取数据2')
			this.getList()
		},
		methods: {
			// 获取信息
			getList() {
				jdf().then(res => {
					if(res.data.length == 0){
						this.hidden = true
					}else{
						this.list = res.data
						this.hidden = false
					}
				})
			},
			getChoose(rp,name,arr){
				// console.log(rp,name,arr)
				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[pages.length - 2]; // 前一个页面
				let lists = arr.map(function(item) {
				    return {
				        id: item.yid,
				        danwei: item.danwei,
				        value: item.name,
						yongfaId:'',
						yongfaName:'',
						num:item.num
				    }
				});
				this.$nextTick(() => {
					if (beforePage.route == 'pages/prescription/search2') {
						beforePage.$vm.arrayId1 = rp,//替换上个页面参数
						beforePage.$vm.arrayName1 = name,//替换上个页面参数
						beforePage.$vm.list = lists,//替换上个页面参数
						uni.navigateBack()
					}
				})
			},
			btnClick() {
				console.log('添加常用方')
				uni.navigateTo({
					url: './add?type=1'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tab {
		padding-bottom: 30upx;

		.commonlyItem {
			padding: 40upx 0;
			border-bottom: 2upx solid #E5E5E5;

			.title {
				font-size: 32upx;
				font-family: Source Han Sans CN;
				font-weight: bold;
				margin-bottom: 20upx;
			}

			.commonly {
				width: 100%;
				font-size: 28upx;
				font-family: Source Han Sans CN;
				font-weight: 400;
				line-height: 56upx;
				color: #7B7B7B;

				.text {
					background: #F4F4F6;
					// display: inline-block;
					padding: 6upx 8upx;
					font-size: 24upx;
					font-family: Source Han Sans CN;
					font-weight: 400;
					color: #9F9F9F;
					margin-right: 10upx;
				}

			}
		}
	
		.based{
			text-align: center;
			padding-top: 30upx;
			font-size: 30rpx;
		}
	}
</style>
